package com.teziyou.commodity.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.thrift.TException;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.mytravel.commodityBridge.service.bean.AdvicedTicketLeftCategory;
import com.mytravel.commodityBridge.service.ScenicSpotInfoService;
import com.mytravel.commodityBridge.service.bean.ScenicSpot;
import com.teziyou.commodity.core.thrift.ConnectionManager;

@SuppressWarnings("rawtypes")
@Service
//public class SceneService extends ScenicSpotInfoService.Client {

public class SceneService {

	@Resource(name="productConnectionManager")
	private ConnectionManager connectionManager;
	
	private ScenicSpotInfoService.Client client;

	public void addScene(ScenicSpot scene) {
		try {
			client.addScene(scene);
		} catch (TException e) {
			throw new RuntimeException(e);
		}
	}

	public boolean deleteSceneById(long id) {
		try {
			return client.deleteSceneById(id);
		} catch (TException e) {
			throw new RuntimeException(e);
		}
	}

	public boolean updateScene(ScenicSpot scene) {
		try {
			return client.updateScene(scene);
		} catch (TException e) {
			throw new RuntimeException(e);
		}
	}

	public List findScenesByPage(
			Map<String, String> condition) {
		try {
			return JSON.parseArray(client.findScenesByPage(condition));
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public int findScenesCount(Map<String, String> condition) {
		try {
			return client.findScenesCount(condition);
		} catch (TException e) {
			throw new RuntimeException(e);
		}
	}

	public Map findSceneById(long id) {
		try {
			return JSON.parseObject(client.findSceneById(id));
		} catch (TException e) {
			throw new RuntimeException(e);
		}
	}

	public List<String> getImageListByMap(Map<String, String> paramMap) {
		try {
			return client.getImageListByMap(paramMap);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public String getImageListStringByMap(Map<String, String> paramMap) {
		try {
			return client.getImageListStringByMap(paramMap);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	public String selectAdvicedCategorybyDictionaryid(String dictionaryid) {
		try {
			Map<String, String> paramMap = new HashMap<String, String>();
			paramMap.put("isOK", "1");
			paramMap.put("dictionary_id", dictionaryid);
			
			return client.selectAdvicedTicketLeftCategory(paramMap);
			
			
			
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	

	public boolean addAdvicedCategory(int dictionaryId, int dicDictionaryId) {
		try{
			
			
			AdvicedTicketLeftCategory bean = new AdvicedTicketLeftCategory();
			bean.setDictionaryId(dictionaryId);
			bean.setDicDictionaryId(dicDictionaryId);
			bean.setIsok(1);
			bean.setListOrder(dicDictionaryId); //随便写一个排序... 
			return client.addAdvicedTicketLeftCategory(bean);
			
		}catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	}
	public boolean delAdvicedCategory(int id) {
		// TODO Auto-generated method stub
		try{
			return client.delAdvicedTicketLeftCategoryById(id);
			
		}catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	}
	
	//保存主题推荐

	public boolean addScenicspots(List<com.mytravel.commodityBridge.service.bean.AdvicedScenicspotCategory> beanList) {
		try {
			return  client.addAdvicedScenicspotCategoryList(beanList);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	//删除主题推荐
	public boolean deleteScenicspotsById(List<Integer> ids) {
		try {
			return client.delAdvicedScenicspotCategoryByIds(ids);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	//查询主题推荐
	public String findScenicspots(Map<String,String> condition) {
		try {
			return client.selectAdvicedScenicspotCategory(condition);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}
